<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Programmers</title>
<meta name="keywords" content="" />
<meta name="description" content="" />

<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="header">
	<div id="menu">
		<ul>
			<li><a href="index.php" class="first">Homepage</a></li>
			<li><a href="forum.php">Forum</a></li>
			<li><a href="login.php">Login</a></li>
			<li><a href="register.php">Register</a></li>
		</ul>
	</div>
	<!-- end #menu -->
</div>
<!-- end #header -->
<div id="logo">
	<h1><a href="#">Public Object Oriented Programming </a></h1>
	<p><em>Programming</em></p>
</div>
<hr />
<!-- end #logo -->
<div id="page">
	<div id="page-bgtop">
		<div id="page-bgbtm">
			<div id="content">
				<div class="post">
					<div class="post-bgtop">
						<div class="post-bgbtm">
							<h2 class="title"><a href="#">Login</a></h2>
							
							
<?php

	include_once 'functions.php';
	$errorMessage = '';
	if(isset($_POST['submit']))
	{
		$errorMessage = "";

		if(empty($_POST['username']))
		{
			$errorMessage .= "You need to enter a username!<br/>";
			$errorMessage .= "<br/>";
		}
		if(empty($_POST['password']))
		{
			$errorMessage .= "You need to enter a password!";
		}

		$username = trim($_POST['username']);
		$password = trim($_POST['password']);

		if(empty($errorMessage))
		{
				//check username/password against record

				if(validateUser($username,$password))
				{
					session_start();
					$_SESSION['username'] = $username;
					$successMessage = 'You have logged in successfully';
				}
				else 
				{
					$username = "";
					$password = "";
					$errorMessage .= "You entered a wrong username or password";
				}
			}
		}
 ?>
							

							
							<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> 
								<label for="username">Username:</label></br>
								<input type="text" title="Enter your Username" name="username" /></br>
								<label for="password">Password:</label> </br>
								<input type="password" title="Enter your password" name="password" /></br>
								<input type="submit" name="submit" value="login" /><input type="button" value="Register" onClick="register.php'">	
							</form>
<?php
	if(!empty($errorMessage))
	{
		echo($errorMessage);
	}
	if(!empty($successMessage))
	{
		echo($successMessage);
	}
?>				
							<div class="entry">
								<p></p>
								<p></p>
							</div>
						</div>
					</div>
				</div>
				
			</div>
			<!-- end #content -->
			<div id="sidebar">
				<ul>
					<li>
						<h2>Bibendum  ornare </h2>
						<ul>
							<li><a href="#">Nec metus sed donec</a></li>
							<li><a href="#">Magna lacus bibendum mauris</a></li>
							<li><a href="#">Velit semper nisi molestie</a></li>
							<li><a href="#">Eget tempor eget nonummy</a></li>
							<li><a href="#">Nec metus sed donec</a></li>
							<li><a href="#">Velit semper nisi molestie</a></li>
							<li><a href="#">Eget tempor eget nonummy</a></li>
							<li><a href="#">Nec metus sed donec</a></li>
						</ul>
					</li>
					<li>
						<h2>Pellenteque ornare </h2>
						<ul>
							<li><a href="#">Nec metus sed donec</a></li>
							<li><a href="#">Magna lacus bibendum mauris</a></li>
							<li><a href="#">Velit semper nisi molestie</a></li>
							<li><a href="#">Eget tempor eget nonummy</a></li>
							<li><a href="#">Nec metus sed donec</a></li>
							<li><a href="#">Velit semper nisi molestie</a></li>
							<li><a href="#">Eget tempor eget nonummy</a></li>
							<li><a href="#">Nec metus sed donec</a></li>
						</ul>
					</li>
					<li>
						<h2>Turpis nulla</h2>
						<ul>
							<li><a href="#">Nec metus sed donec</a></li>
							<li><a href="#">Magna lacus bibendum mauris</a></li>
							<li><a href="#">Velit semper nisi molestie</a></li>
							<li><a href="#">Eget tempor eget nonummy</a></li>
							<li><a href="#">Nec metus sed donec</a></li>
							<li><a href="#">Nec metus sed donec</a></li>
							<li><a href="#">Magna lacus bibendum mauris</a></li>
						</ul>
					</li>
				</ul>
			</div>
			<!-- end #sidebar -->
		</div>
	</div>
</div>
<div id="footer">
	<p>Copyright (c) Josh, Desh, Viet and Desmond</a>.</p>
</div>
<!-- end #footer -->
</body>
</html>
